package com.csun.nusing.ui.activity;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.csun.nusing.R;
import com.csun.nusing.presenter.NursingAlarmAnswerPresenter;
import com.csun.nusing.presenter.inter.IBase;
import com.csun.nusing.ui.BaseActivity;
import com.csun.nusing.ui.myview.RoundImageView;

/**
 * 报警回馈界面
 * ClassName: NursingAlarmAnswerActivity
 * @Description: TODO
 * @author fzq
 * @date 2017-10-28
 */
public class NursingAlarmAnswerActivity extends
		BaseActivity<NursingAlarmAnswerPresenter> implements IBase {

	private TextView comfirmbtn;
	private RatingBar ratingbar;
	private int currentrating;
	private String alarmid;// 报警id
	private RadioGroup answerrg;
	private String result = "1";
	private EditText answeret;
	private String alertId;
	private RoundImageView photoicon;
	private TextView oldname;
	private String alertOlderName;
	private String alertOlderPic;

	@Override
	public int getContentViewId() {
		return R.layout.activity_nursing_alarm_answer;
	}

	@Override
	public void initSubViews(View view) {
		// TODO Auto-generated method stub
		super.initSubViews(view);
		findView();
	}

	/**
	 * 初始化控件
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-10-28
	 */
	private void findView() {
		photoicon = findViewById(R.id.activity_alarm_answer_photo_icon);
		oldname = findViewById(R.id.activity_alarm_answer_oldname);
		comfirmbtn = findViewById(R.id.nursing_alarm_answer_comfirm_tv);
		ratingbar = findViewById(R.id.nursing_alarm_answer_ratingbar);
		answerrg = findViewById(R.id.nursing_alarm_answer_rg);
		answerrg.check(R.id.nursing_alarm_answer_one_rb);
		answeret = findViewById(R.id.nursing_alarm_answer_et);
		comfirmbtn.setOnClickListener(new click());
		answerrg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.nursing_alarm_answer_one_rb:
					result = "1";
					break;
				case R.id.nursing_alarm_answer_two_rb:
					result = "0";
					break;
				case R.id.nursing_alarm_answer_three_rb:
					result = "2";
					break;	
				default:
					break;
				}
			}
		});
	}

	@Override
	public void initData() {
		super.initData();
		alertId = getIntent().getStringExtra("alertId");
		alertOlderName = getIntent().getStringExtra("AlertOlderName");
		alertOlderPic = getIntent().getStringExtra("AlertOlderPic");
		Glide.with(this).load(alertOlderPic).into(photoicon);
		oldname.setText(""+alertOlderName);
	}
	/**
	 * 点击事件
	 * ClassName: click 
	 * @Description: TODO
	 * @author fzq
	 * @date 2017-11-2
	 */
	private class click implements OnClickListener {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.nursing_alarm_answer_comfirm_tv:
				enter();
				break;
			default:
				break;
			}
		}

	}

	/**
	 * 提交反馈
	 * 
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-10-28
	 */
	public void enter() {
		currentrating = (int) ratingbar.getRating();
		mPresenter.enter(this, ""+alertId, ""+result, currentrating + "", ""+answeret
				.getText().toString());
	}
	
	@Override
	protected NursingAlarmAnswerPresenter getPresenter() {
		return new NursingAlarmAnswerPresenter(this);
	}

}
